package com.zhoug.widget.popup;

import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;

import com.zhoug.common.utils.AppUtils;


/**
 * @Author 35574
 * @Date 2020/5/8
 * @Description
 */
public class PopupWindowHelper {

    /**
     * 测量大小 如果窗口宽高为0则测量宽高
     * @param popupWindow
     */
    public static void measureWindowSize(PopupWindow popupWindow){
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
            if(popupWindow.getWidth()<=0 || popupWindow.getHeight()<=0){
                View contentView = popupWindow.getContentView();
                AppUtils.measureView(contentView);
                if(popupWindow.getWidth()<=0){
                    popupWindow.setWidth(contentView.getMeasuredWidth());
                }
                if(popupWindow.getHeight()<=0){
                    popupWindow.setHeight(contentView.getMeasuredHeight());
                }
            }
        }
    }
}
